//
//  PurchaseProductCell.m
//  iShop
//
//  Created by svp on 26/12/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "PurchaseProductCell.h"


@implementation PurchaseProductCell

@synthesize productField = _productField;
@synthesize amountField = _amountField;
@synthesize maxAmount = _maxAmount;
@synthesize delegate = _delegate;

-(BOOL) initPickerWithArray:(NSArray*) array
{
	if (!_pickerArray) {
		_pickerArray = [array copy];
		_pickerView = [[UIPickerView alloc] init];
		_pickerView.showsSelectionIndicator = YES;
		_productField.inputView = _pickerView;
		_pickerView.delegate = self;
	}
	else
	{
		[_pickerArray release];
		_pickerArray = nil;
		_pickerArray = [array copy];
		[_pickerView reloadAllComponents];
	}	
	return YES;
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
	return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
	return _pickerArray.count;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
	return [_pickerArray objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
	_selectedIndex = row;
	_productField.text = [_pickerArray objectAtIndex:row];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
	if (_delegate && [_delegate respondsToSelector:@selector(textFieldDidBeginEditing:)]) {
		[_delegate textFieldDidBeginEditing:self];
	}
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
	if (_delegate && [_delegate respondsToSelector:@selector(textFieldDidBeginEditing:)]) {
		[_delegate textFieldDidEndEditing:self];
	}
}
	

@end
